GIS 学会 FOSS4G 分科会ワークショップ
「Geocomputation with R 勉強会」
10月29日(土) 9:30 - 12:00
報告


事後アンケートは用意しなかった。
コードを実行するだけでは何をしているか分かりづらい。
あらためて講義を録画して、YouTube (無料)か Udemy などで公開すると良いかもしれない。
年に数回、対面で勉強会したい。
(京都の知人で参加できなかった方が、有料でもよいので京都でやってくれと言っています。)
S2 については、もっと勉強する必要がある。
日本のデータで試したい
パッケージを作成しました

library(geojp)
library(sf)
# 旭川市 (01, 204), 鹿児島市 (46, 201)
strTempDir <- "~/data.noindex"
sfFukushi <- geojp::read_landnuminfo_welfare("01", "204", data_dir = strTempDir)## [1] "Downloaded the file and saved in https://nlftp.mlit.go.jp/ksj/gml/data/P14/P14-21/P14-21_01_GML.zip"
## [1] "Found a geojson file: /var/folders/q2/grwlh1bn27l2t43bqg7dxhwr0000gn/T//RtmpM0eOrL/P14-21_01.geojson"
## [1] "Downloaded the file and saved in https://nlftp.mlit.go.jp/ksj/gml/data/L01/L01-21/L01-21_01_GML.zip"
## [1] "Found a geojson file: /var/folders/q2/grwlh1bn27l2t43bqg7dxhwr0000gn/T//RtmpM0eOrL/*L01-21_01*.geojson"
## [1] "Found a geojson file: /var/folders/q2/grwlh1bn27l2t43bqg7dxhwr0000gn/T//RtmpM0eOrL/L01-21_01_GML\\L01-21_01.geojson"
## [1] "「国土数値情報(福祉施設データ)」(国土交通省)"
## [1] "「国土数値情報(地価公示データ)」(国土交通省)"

Google による球面幾何学ライブラリ
GEOS は平面幾何学
S2 に対応しているのは、現状では R のみ
library(sf)
# Spatial join (point - point) with S2
sf::sf_use_s2(TRUE)
start_time = Sys.time()
nearest_point = sf::st_nearest_feature(sfFukushi,sfChika)
sfFukushi$L01_006_S2 <- sfChika[nearest_point,"L01_006"]$L01_006
sfFukushi$dist_Chika_S2 = sf::st_distance(sfFukushi, sfChika[nearest_point,], by_element=TRUE)
Sys.time() - start_time## Time difference of 0.4416351 secs
# Spatial join (point - point) with GEOS
sf::sf_use_s2(FALSE)
start_time = Sys.time()
nearest_point = sf::st_nearest_feature(sfFukushi,sfChika)
sfFukushi$L01_006_GEOS <- sfChika[nearest_point,"L01_006"]$L01_006
sfFukushi$dist_Chika_GEOS = sf::st_distance(sfFukushi, sfChika[nearest_point,], by_element=TRUE)
Sys.time() - start_time## Time difference of 1.297735 mins
# Compare S2 and GEOS
t.test(as.numeric(sfFukushi$dist_Chika_S2), as.numeric(sfFukushi$dist_Chika_GEOS), paired = TRUE)##
## Paired t-test
##
## data: as.numeric(sfFukushi$dist_Chika_S2) and as.numeric(sfFukushi$dist_Chika_GEOS)
## t = -27.767, df = 12200, p-value < 2.2e-16
## alternative hypothesis: true difference in means is not equal to 0
## 95 percent confidence interval:
## -7.456647 -6.473297
## sample estimates:
## mean of the differences
## -6.964972